
/*
 * Form.java
 *
 * Created on September 30, 2008, 10:05 AM
 */

package disk;

import java.io.*;
import java.util.*;
import javax.swing.tree.*;
import javax.swing.event.* ;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


import java.net.*;

  /**
 *
 * @author  limited
 */
public class Form extends javax.swing.JFrame implements TreeSelectionListener {
    static boolean analysisFlag=false;
    static String nextTofind;
    static boolean inc=false;
    static int stats=0;
    static int unstats=0;
    Form f;
    int vval;
  /** Creates new form Form */
 public Form() {
        initComponents();
        setResizable(false);
        try{
      r  =new PrintWriter("analysis.gdl");
      prw=new PrintWriter("rt.gdl");
        }
        catch(Exception e)
        {}
        f=this;        
    }
    
 public void printDataRun(String mft)
  {
    
     try{
                 Runtime rt = Runtime.getRuntime() ;
 				Process p = rt.exec("Disk.exe d "+mft+" "+bootIndex) ;
 				BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream() ));
 				String h=in.readLine();
                               
                                 while(h!=null)
                                {
                                    System.out.println(h);
                                    h=in.readLine();
                                 }
     }
     catch(Exception e)
     {
        e.printStackTrace();
     }
    }
  /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        setJMenuBar(mB); 
        JMenu fil=new JMenu("Task");
        JMenuItem MFTS = new JMenuItem("MFT Scan");
        JMenuItem ana=new JMenuItem("Analysis");
        JMenuItem getTime=new JMenuItem("Get ALL Time");
        fil.add(MFTS);
        fil.add(ana);
        fil.add(getTime);
        mB.add(fil);
        
        getTime.addActionListener(new ActionListener()
        {    
                public void actionPerformed(ActionEvent ae)
        {
                Component cmp[]=jp.getComponents();
                String tmpDate="";
                String tmpCat="";
                for(int u=0;u<cmp.length;u++)
                {
                    try
			{
                        
                        if(cmp[u] instanceof JButtonExtended)
                        {
                                JButtonExtended ll=(JButtonExtended)cmp[u];
                                
                                Runtime rt = Runtime.getRuntime() ;
 				Process p = rt.exec("Disk.exe t "+ll.sector+" "+bootIndex) ;
 				BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream() ));
 				String h=in.readLine();
                                
 				while(h!=null)
 				{
                                    if(((ll.getIcon()).toString()).startsWith("unuse.jpg"))
                                {
                                    if(h.startsWith("GotLast"))
                                    
                                    {
                                        System.out.println("Got Last "+(h.split(" "))[1]);
                                        tmpDate=(h.split(" "))[1];
                                        tmpCat=":D";
                                    }    
                                }
                                    else
                                    if(h.startsWith("GotCrea"))
                                    {
                                        System.out.println("Got Date "+(h.split(" "))[1]);
                                        tmpDate=(h.split(" "))[1];
                                         tmpCat="";
                                    }
                                    
 					h=in.readLine();
 				}
 				
 
 
				 p.destroy() ;
                        }
                        else
                        {
                            if(tmap.containsKey(tmpDate))
                                ((Vector)tmap.get(tmpDate)).add(((JLabel)cmp[u]).getText()+tmpCat);
                            else
                            {
                                Vector rt=new Vector();
                                rt.add(((JLabel)cmp[u]).getText()+tmpCat);
                                tmap.put(tmpDate,rt );
                            }
                            
                        }
                 }
                 catch(Exception ex){
                     
                     ex.printStackTrace();
                 
                 } 
                }
                
                reCreateNew();
                //System.out.println(tmap);
        }
                
        }       );
                
        MFTS.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
                 part = JOptionPane.showInputDialog(null, "Partiion", "Enter Partition Label", JOptionPane.QUESTION_MESSAGE);
                 sectorToMFT=new Hashtable();
                 
                 root.removeAllChildren();
                 rootI.removeAllChildren();
                 jp.removeAll();
                   
                 try{
                 Runtime rt = Runtime.getRuntime() ;
 				Process p = rt.exec("Disk.exe s "+part) ;
 				BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream() ));
 				String h=in.readLine();
                               
                                 while(h!=null)
                                {
                                    System.out.println(h);
                                     if(h.startsWith("Special"))
                                     {
                                      
                                      String arr[]=  h.split(" ");
          
                                      hs2.put(arr[3],arr[1]);
                                      hs3.put(arr[3],arr[4]);
                                      sectorToMFT.put(arr[3],arr[5]);
                                      MFTSeq.put(arr[3],arr[6]);
                                     // printDataRun(arr[3]);
                                      if(!hs.containsKey(arr[2]))
                                         {
                                           Vector v=new Vector();
                                           v.add(arr[3]);
                                           hs.put(arr[2], v);
                                        }
                                        else
                                            {
                                             Vector v=(Vector)hs.get(arr[2]);
                                             v.add(arr[3]);
                                            }
                                     }
                                     else if(h.startsWith("BootIndex"))
                                     {
                                      System.out.println(h);
                                      String arr[]=  h.split(" ");
                                      bootIndex=arr[1];
                                     }
                                     else if(h.startsWith("RootMFT"))
                                     {
                                      System.out.println(h);
                                      String arr[]=  h.split(" ");
                                      rootMFT=arr[1];
                                      System.out.println("Root J "+rootMFT);
                                      vval=Integer.parseInt(rootMFT.substring(rootMFT.length()-2, rootMFT.length()));
                                     }
                                         h=in.readLine();
                                  }
                                
  
         p.destroy();
         
         p = rt.exec("Disk.exe l 0 "+bootIndex) ;
         in = new BufferedReader(new InputStreamReader(p.getInputStream()));
 	 h=in.readLine();
         IndexMace lr=null;
         String arr[]=new String[5];
         String pValue="";
         String nwLSN="";
         while(h!=null)
         {
               System.out.println(h);
               
               if(h.startsWith("LogFileMFT"))
               {
                   arr=  h.split(" ");
                   System.out.println("CompareTo "+(String)seqLogFileMFT.get(arr[1])+" "+arr[2]);
                   if(((Integer.parseInt((String)MFTSeq.get(arr[1]))) >= (Integer.parseInt(arr[2]))) && ((seqLogFileMFT.containsKey(arr[1]) && ((Integer.parseInt((String)seqLogFileMFT.get(arr[1]))) <= (Integer.parseInt(arr[2]))))|| !seqLogFileMFT.containsKey(arr[1])))
                        { 
                       
                       pValue=(String)seqLogFileMFT.get(arr[1]);
                        seqLogFileMFT.put(arr[1],arr[2]);
                                              
                      }
                    else
                        {
                        h=in.readLine() ;
                        System.out.println("Not Gone - Below Bluff");
                        lr=null;
                         nwLSN="";
                        continue;
                        }
                   
                    
                    lr=new IndexMace();
                    
               }
               if(h.startsWith("LSN"))
               {
                   nwLSN=h.substring(4);
                  
               }
                if(h.startsWith("cre")&&lr!=null)
                       lr.Crea=h.substring(3);
                if(h.startsWith("Mod")&&lr!=null)
                       lr.Mod=h.substring(3);
                if(h.startsWith("MFT")&&lr!=null)
                       lr.MFT=h.substring(3);
                if(h.startsWith("Acc")&&lr!=null)
                {
                    lr.last=h.substring(3);
                    logMFTHash.put(arr[1], lr);
                    LSNSector.put(new LSNString(nwLSN),arr[1]);
                    lr=null;
                    nwLSN="";
                }
               if(h.startsWith("creString")&&lr!=null)
               {
                    if(logFileMFTEarliest.containsKey(arr[1]) )
                   {
                        if((((LSNString)logFileMFTEarliest.get(arr[1])).compareTo(new LSNString(nwLSN))<0) &&((Integer.parseInt((String)MFTSeq.get(arr[1])))==(Integer.parseInt(pValue))) )
                        {
                            
                            lr=null;
                             nwLSN="";
                        }
                   }
                   else
                   logFileMFTEarliest.put(arr[1],new LSNString(nwLSN));
               }
             h=in.readLine() ;
               
         }
       
      //  System.out.println(hs.get("6291529"));
       root.sector=rootMFT;
       root.removeAllChildren();
       rootI.removeAllChildren();
       jTree2.updateUI();
       jTree1.updateUI();
       
       
       addChildsOfNode(root);
       jTree2.updateUI();
       jTree1.updateUI();
 				
        System.out.println("Sequence LSN Records "+LSNSector);                        
                               
                 }
                 catch(Exception e)
                 {
                 e.printStackTrace();
                 }
            }
        }
        );
        ana.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae)
            {
           a=new Analysis(f);
           
            a.setVisible(true);
                       
            }
          }
    );
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree(root);
        jScrollPane2 = new javax.swing.JScrollPane();
	jScrollPane2.getViewport().add(jp);
	jp.setLayout(null);
	jTree1.addTreeSelectionListener(this);
        jTree2 = new javax.swing.JTree(rootI);
	jTree2.addTreeSelectionListener(new TreeSelectionListener(){

		public void valueChanged(TreeSelectionEvent te)
	{
		TreeNodeM tm=(TreeNodeM)jTree2.getLastSelectedPathComponent();
	        System.out.println("Hash "+hs5+" "+tm.name);
                selectedVCN=tm.name;
		if(hh2.containsKey(tm.name))
	{
		Vector v=(Vector)hh2.get(tm.name);
                addVectorToPane(v);
	}
	}
	}
	);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
       
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel19.setText("Index Info.");
        
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jLabel40 = new javax.swing.JLabel();
        jLabel40.setText("LogFile Timestamps.");
        
	   jScrollPane3 = new javax.swing.JScrollPane();
           jScrollPane4 = new javax.swing.JScrollPane();
           jTree3=new JTree(root3);
      

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jScrollPane1.setViewportView(jTree1);

        jLabel7.setText("Creation");
        jLabel8.setText("Modifica.");
        jLabel9.setText("MFT");
        jLabel10.setText("Last Acc.");
        jLabel15.setText("n/a");
        jLabel16.setText("n/a");
        jLabel17.setText("n/a");
        jLabel18.setText("n/a");
        
        jLabel20.setText("Creation");
        jLabel21.setText("Modifica.");
        jLabel22.setText("MFT");
        jLabel23.setText("Last Acc.");
        jLabel24.setText("          n/a");
        jLabel25.setText("          n/a");
        jLabel26.setText("          n/a");
        jLabel27.setText("          n/a");
        jLabel28.setText("MFT Status:");
        jLabel29.setText("n/a");
        jLabel30.setText("MFT Entry:");
        jLabel31.setText("n/a");
        
        jLabel32.setText("Creation");
        jLabel33.setText("Modifica.");
        jLabel34.setText("MFT");
        jLabel35.setText("Last Acc.");
        jLabel36.setText("          n/a");
        jLabel37.setText("          n/a");
        jLabel38.setText("          n/a");
        jLabel39.setText("          n/a");
        
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(63, 63, 63)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel18,200,200,200))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel9)
                            )
                        .addGap(26, 26, 26)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel15,200,200,200)
                            .addComponent(jLabel16,200,200,200)
                            .addComponent(jLabel17,200,200,200))))
                         
                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel23)
                        .addGap(25, 25, 25)
                        .addComponent(jLabel27,200,200,200)
                       
                        /*.addComponent(jLabel28)
                       .addGap(20, 20, 20)
                        .addComponent(jLabel29)
                        .addGap(50, 50, 50)
                        .addComponent(jLabel30)
                       .addGap(20, 20, 20)
                        .addComponent(jLabel31)*/
                        )
                       
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel20)
                            .addComponent(jLabel21)
                            .addComponent(jLabel22)
                            )
                        .addGap(26, 26, 26)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel24,200,200,200)
                            .addComponent(jLabel25,200,200,200)
                            .addComponent(jLabel26,200,200,200))))
                           
              .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel35)
                         .addGap(25, 25, 25)
                        .addComponent(jLabel39,200,200,200)
                      
                        )
                        
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel32)
                            .addComponent(jLabel33)
                            .addComponent(jLabel34)
                            )
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel36,200,200,200)
                            .addComponent(jLabel37,200,200,200)
                            .addComponent(jLabel38,200,200,200))))
                            
                )
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel17))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel18)))
                    
                 .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(jLabel24))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jLabel25))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(jLabel26))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jLabel27)
                   
                   // .addComponent(jLabel28)
                   
                   // .addComponent(jLabel29)
                     //.addComponent(jLabel30)
                      //.addComponent(jLabel31)
                    )
                    )
                    
                     .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel32)
                    .addComponent(jLabel36))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel33)
                    .addComponent(jLabel37))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel34)
                    .addComponent(jLabel38))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel35)
                    .addComponent(jLabel39)
                   
                 
                    )
                    )
        );

        jLabel1.setText("Standard Information");

        jLabel2.setText("Creation");

        jLabel3.setText("Modifica.");

        jLabel4.setText("MFT");

        jLabel5.setText("Last Acc.");

        jLabel6.setText("File Name Info.");
        
        jLabel11.setText("n/a");

        jLabel12.setText("n/a");

        jLabel13.setText("n/a");

        jLabel14.setText("n/a");

        jScrollPane3.setViewportView(jTree2);
        jScrollPane4.setViewportView(jTree3);
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 543, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                       // .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                        )
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel5)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addGap(16, 16, 16)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel11)
                                        .addComponent(jLabel12))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.LEADING)))))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(115, 115, 115)
                                .addComponent(jLabel6)
                                .addGap(270, 270, 270)
                                 .addComponent(jLabel19)
                                  .addGap(230, 230, 230)
                                 .addComponent(jLabel40)
                                 ))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 467, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                       //    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                            
                            )
                            )
                             
                             )
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel6)
                            .addComponent(jLabel19)
                            .addComponent(jLabel40)
                            )
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGap(13, 13, 13))
        );
	




        pack();
    }// </editor-fold>                        
    
 public void reCreateNew()  {
        
      try{
          Iterator i=(tmap.keySet()).iterator();
      
        String dir="E:\\Dir";
        File dirt =new File(dir);
        File f=null;
            if(!dirt.exists())
		dirt.mkdir();
        
        while(i.hasNext())
        {
            String time=(String)i.next();
            if(time.equals("0"))
                continue;
            Vector r=(Vector)(tmap.get(time));
            for(int y=0;y<r.size();y++)
            {
                String tmp=(String)r.get(y);
                
                if(tmp.endsWith(":D"))
                {
                    tmp=tmp.split(":D")[0];
                    f=new File(dir+"\\"+tmp);
                    if(f.exists())
                        f.delete();
                    else
                    {
                        f.createNewFile();
                        f.delete();
                    }
                    
                } 
                else
                {
                    f=new File(dir+"\\"+tmp);
                    f.createNewFile();
                }
            }
        }
  
  }
      catch(Exception e)
      {
        e.printStackTrace();
      }
  }   
 
 public static  int compareIndex(String a,String b)
	{
		int i=0,j=0;
		String tmp="";
		while(i< (tmp= a.length()>b.length()?b:a ).length()	)
		{
			if(a.charAt(i)==b.charAt(i))
				{
								
					if(tmp.charAt(i)=='/')
						j++;
						
					i++;
				}
			else
			 return j;	
			
		}
		return j;
		
	}

public  static class FormAnalysis extends Thread{
    
    String p[];
    String p2[];
    int y=0;
    
    FormAnalysis(String p[] ,String []p2,int z)
    {
        this.p=p;
        this.p2=p2;
        this.y=z;
        
    }
    
    public void run()
    {
        while(y<p.length&&y<p2.length)
      {
           String tmp=null;
          if((tmp=compareInRelation(p[y],p2[y]))!=null)
          {
              System.out.println(tmp+" firstRelation");
          }
           
          if((tmp=findInLogFile(p[y],p2[y]))!=null)
              {
                  System.out.println(tmp+" firstLog");
                  break;
              }
           y++;
        }
    }
}

 public static void analysis(String path,String path2,boolean full) throws Exception  {
       
       entryMap.clear();
       vertices.clear();
       edges.clear();
       mapList.clear();
       inc=full;
       r=new PrintWriter("analysis.gdl");
       String p[]=path.split("/");
       String p2[]=path2.split("/");
       
      int y=0;
      lastVisited=root;
      System.out.println("Root Analysis "+root);
      analysisFlag=true;
      //a.graph=new SparseGraph();
      AnalysisVertex rootA = new AnalysisVertex("Root");
      //a.graph.addVertex(rootA);
      last=rootA;
      mapList.put(last, grp+"");
      vertices.add(grp+" Root");
      grp++;
       int toTraverse=compareIndex(path,path2);
       System.out.println("To Traverse "+toTraverse);
      while(y<p.length&&y<p2.length)
      {
          
          if(y<toTraverse)
              lastVisited=findNode(lastVisited,p[y]);
          else
          {
          FormAnalysis fa=new FormAnalysis(p,p2,y);
          fa.start();
          break;
          }
            
          y++;
      }
       
    addAllToFile();
    /* a.renderGraph();
       a.repaint();
       a.vv.restart();
      */
//       System.out.println("Relation "+a.graph.getEdges());
       analysisFlag=false;
       grp=1;
       yu=0;
       
   }
 
 public static String compareInRelation(final String cmp1,final String cmp2)
 {
     
        //Analysis.jtext.setText("");
        Analysis.jtext.append("\n\n\nScanning Index Records for Correlation.");
                     
 

 dt.resume();
     
 Enumeration ei=relation.keys();
 while(ei.hasMoreElements())
 {
    Vector vv=(Vector)ei.nextElement();
    Vector vv2=(Vector)relation.get(vv);
    if(findEntryIn(vv,cmp1)&&findEntryIn(vv2,cmp2))
    {
     
        dt.suspend();
       
        Analysis.jtext.append("\nRelation between path found "+ cmp1 +" -> "+cmp2);
        
                           
        return cmp1;
    }
    else if(findEntryIn(vv,cmp2)&&findEntryIn(vv2,cmp1))
    {
        dt.suspend();
        
        Analysis.jtext.append("\nRelation between path found "+ cmp2 +" -> "+cmp1);
        
                           
        
        return cmp2;
    }
    
    
 }
 dt.suspend();
 
        Analysis.jtext.append("\nNo relation between path found");
        

 
 
 System.out.println("compareInRelation "+null);
 return null;
 }
 
 public static String findInLogFile(final String cmp1,final String cmp2)
 {
     
     String cpm1=(String)nameMFTvalueChanged.get(cmp1);
     String cpm2=(String)nameMFTvalueChanged.get(cmp2);
     
    
         Analysis.jtext.append("\nScanning Log File Records for Correlation.");
                       

 dt.resume();
    
    
     System.out.println("cpmS "+cpm1+" "+cpm2);
    Vector c=new Vector(LSNSector.values());
    System.out.println("LSNVEctor "+c);
     if(cpm1!=null&&cpm2!=null)
     {
        
        if(c.contains(cpm1)&&c.contains(cpm2))
            if(c.indexOf(cpm1)>c.indexOf(cpm2))
            {
                 dt.suspend();
               
                 Analysis.jtext.append("\nRelation between path found "+ cmp2 +" -> "+cmp1);
                                
                
               
                return cmp2;
            }
            else if(c.indexOf(cpm1)<c.indexOf(cpm2))
            {
             
                dt.suspend();
             
        
                  Analysis.jtext.append("\nRelation between path found "+ cmp1 +" -> "+cmp2);
                                   
               
                
                return cmp1;
            }
     }
    dt.suspend();
    
                   Analysis.jtext.append("\nNo relation between path found");
        
   
  
    System.out.println("findInLogFile "+c.contains(cpm1)+" "+c.contains(cpm2));
    return null;
    
 }
 
 public static void main(String args[]) throws Exception {
        
       /* BufferedReader br=new BufferedReader(new FileReader("FileName.txt"));
        String h=br.readLine();
      
        while(h!=null)
        {
          String arr[]=  h.split(" ");
          
          hs2.put(arr[2],arr[0]);
          hs3.put(arr[2],arr[3]);
          
          if(!hs.containsKey(arr[1]))
          {
              Vector v=new Vector();
              v.add(arr[2]);
              hs.put(arr[1], v);
          }
          else
          {
            Vector v=(Vector)hs.get(arr[1]);
            v.add(arr[2]);
          }
          h=br.readLine();
        }
        
      //  System.out.println(hs.get("6291529"));
       root=new TreeNodeM("Root","6291529");
       rootI=new TreeNodeM("IndexRoot","na");*/
      // addChildsOfNode(root);
        
        
        root=new TreeNodeM("Root","na");
       rootI=new TreeNodeM("IndexRoot","na");
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
                new Form().setVisible(true);
            }
        });
        
    }
 public  void addVectorToPane(Vector v)  {
      jp.removeAll();
      jp.validate();
      jp.repaint();
      
    System.out.println("Vector "+v);
    int x=20,j=20;
    Iterator i=v.iterator();
    int uu=0;
    while(i.hasNext())
    {
        String newS=(String)i.next();
        String ar[]=newS.split(" ");
        newS=ar[0];
        String flag="unused";
        if(hs3.containsKey(newS))
            flag=(String)hs3.get(newS);
        
           final JButtonExtended l=new JButtonExtended(newS,uu) ;
           uu++;
         l.setMargin(new Insets(-3, -3, -3, -3));
          l.setFocusPainted(false);
        l.setContentAreaFilled(false); 
         l.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            
                 try
			{
                               jLabel15.setText("n/a");
                               jLabel16.setText("n/a");
                               jLabel17.setText("n/a");
                               jLabel18.setText("n/a");
                               
                               jLabel11.setText("n/a");
                               jLabel12.setText("n/a");
                               jLabel13.setText("n/a");
                               jLabel14.setText("n/a");
                               
                              jLabel24.setText("          n/a");
                              jLabel25.setText("          n/a");
                              jLabel26.setText("          n/a");
                              jLabel27.setText("          n/a");
                              
                               jLabel36.setText("          n/a");
                               jLabel37.setText("          n/a");
                               jLabel38.setText("          n/a");
                               jLabel39.setText("          n/a");
                               
                                JButtonExtended  ll=(JButtonExtended ) e.getSource();
                                boolean flag=false;
 				Runtime rt = Runtime.getRuntime() ;
 				Process p = rt.exec("Disk.exe t "+ll.sector+" "+bootIndex) ;
 				BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream() ));
 				String h=in.readLine();
 				while(h!=null)
 				{
                                    if(!flag)
                                    {
                                       
                                        if(h.startsWith("cre"))
                                            jLabel15.setText(h.substring(3));
                                        if(h.startsWith("Mod"))
                                            jLabel16.setText(h.substring(3));
                                        if(h.startsWith("MFT"))
                                            jLabel17.setText(h.substring(3));
                                        if(h.startsWith("Acc"))
                                            jLabel18.setText(h.substring(3));
                                        else if(h.endsWith("16"))
                                        {
                                            flag=true;
                                        }
                                        
                                    }
                                    else
                                    {
                                        if(h.endsWith("48"))
                                        {
                                            flag=false;
                                        }
                                    if(h.startsWith("cre"))
                                            jLabel11.setText(h.substring(3));
                                        if(h.startsWith("Mod"))
                                            jLabel12.setText(h.substring(3));
                                        if(h.startsWith("MFT"))
                                            jLabel13.setText(h.substring(3));
                                        if(h.startsWith("Acc"))
                                            jLabel14.setText(h.substring(3));
                                    
                                    }
 					h=in.readLine();
 				}
 				
                                if(hIndex.containsKey(selectedVCN))
                                {
                                    Vector nv =(Vector)hIndex.get(selectedVCN);
                                    IndexMace imace=(IndexMace)nv.get(l.seqNo);
                                    
                                    jLabel24.setText(imace.Crea);
                                    jLabel25.setText(imace.MFT);
                                    jLabel26.setText(imace.Mod);
                                    jLabel27.setText(imace.last);
                                }
                                
                                if(logMFTHash.containsKey(ll.sector))
                                {
                                   
                                    IndexMace ii=(IndexMace)logMFTHash.get(ll.sector);
                                    jLabel36.setText(ii.Crea);
                                    jLabel37.setText(ii.MFT);
                                    jLabel38.setText(ii.Mod);
                                    jLabel39.setText(ii.last);
                                
                                }
 
				 p.destroy() ;
                 }
                 catch(Exception ex){
                     
                     ex.printStackTrace();
                 
                 }
            
            }
            
            
             
         });
         JLabel l2=null;
         
         if(hs2.containsKey(newS))
            l2=new JLabel((String)hs2.get(newS)+" "+ar[2]);
         else
             l2=new JLabel("Deleted "+ar[2]);
        if(flag.equalsIgnoreCase("dir"))
        {
            
             l.setIcon(new ImageIcon("new2.jpg"));
             
           
           
        }
        else if(flag.equalsIgnoreCase("unused"))
        {
              l.setIcon(new ImageIcon("unuse.jpg"));
        }
        else
            l.setIcon(new ImageIcon("file.jpg"));
        
         if(x>600)
              {
                  j+=120;
                  x=20;
              }
             l2.setBounds(x,j+50,200,100);
             l.setBounds(x,j, 80, 80);
                 jp.add(l );
                 jp.add(l2);
                 jp.setPreferredSize(new Dimension(x,j+120));
                 jp.revalidate();
                 jp.repaint();
                  
                  jScrollPane2.revalidate();
                  jScrollPane2.repaint();
            jScrollPane2.updateUI();
             x+=200;
        
    }
    
    }
 public static TreeNodeM findNode(TreeNodeM lastV,String value)  {
        Enumeration e=lastV.children();
        while(e.hasMoreElements())
        {
            TreeNodeM val=(TreeNodeM)e.nextElement();
            if(val.name.startsWith(value))
            {
                TreeNode f[]=val.getPath();
                TreePath tp=new TreePath(f);
                jTree1.setSelectionPath(tp);
                lastVisited=val;
                return val;
            }
            
            
        }
        return null;
    
    }
 public void addIndexToPane()  {
    jp.removeAll();
      jp.validate();
      jp.repaint();
      
 
      System.out.println("EntryIndex "+entryIndex);
  
  }
 public void doFirstSetOfCorrelation(String tName)  {
 Enumeration e=hh2.keys();  
 Vector key=new Vector(hh2.keySet());
 Vector vs=new Vector(hh2.values());
 int vis=0,setFlag=0,flg=0;
 AnalysisVertex av=null;
 
 while(e.hasMoreElements())
 {
    String r=(String)e.nextElement();
    System.out.println("For VCN "+r);
    int used=0;
   if(hs5.containsKey(r)) 
       used=(Integer)hs5.get(r);
   else
   {
        vis++;
        continue;
   }
    Vector vrs=(Vector)hh2.get(r);
    
    if(vrs.size()<=used)
    {
        vis++;
        continue;
    }
    Vector vr=new Vector(vrs.subList(used,vrs.size()));
    int i=0;
    setFlag=0;
    while(i<vr.size())
    {
        String hr=(String)vr.get(i);
        int y=0;
        while(y<vs.size())
        {
            if(y==vis)
            {
                y++;
                continue;
            }
            Vector ind=(Vector)vs.get(y);
            if(ind.contains(hr))
            {
                System.out.println("Yes it is there "+hr+" "+key.get(y));
                
                if(!inc)
                {
                    System.out.println("Full");
                    ind=new Vector(ind.subList(ind.indexOf(hr),ind.size()));
                }
              
                vr=new Vector(vr.subList(vr.indexOf(hr),vr.size()));
                i=0;int z=0;
             
                Vector indPrev=(Vector)ind.clone();
                ind.removeAll(vr);
                   
                indPrev.removeAll(ind);
                
                relation.put(indPrev, ind);
             //   Verify.verify(indPrev, ind);
                int lno=0;
                if(!findEntryIn(ind,null))
                {
                    if(findEntryIn(indPrev,null))
                
                    {
                        lno=1;
                    }
                }
                else
                        lno=2;
                
                if(flg==0)
                {
                    av=addItToGraph(indPrev,ind,tName,lno);
                    flg=1;
                }
                else
                    addItToGraph(indPrev,ind,av,lno);
                
                setFlag=1;
                break;
            }
            else
                y++;
        }
        if(setFlag==1)
            break;
        i++;
    }
 vis++;
 }
 if(flg!=1)
 {
     AnalysisVertex a1=new AnalysisVertex(tName);
     vertices.add(grp+" "+tName);
     mapList.put(a1,grp+"");
 
     //a.graph.addVertex(a1);
     //a.graph.addEdge(new DirectedSparseEdge(last,a1));
     
         edges.add((String)mapList.get(last)+"->"+grp);
     
     grp++;
     last=a1;
     
     System.out.println("Last Co "+last);
 }
 
 

 
 }
 public AnalysisVertex addItToGraph(Vector indPrev,Vector ind,Object folder,int lno)  {
  
     
     AnalysisVertex a1;
     
     if(folder instanceof String && !entryMap.containsKey(folder) )
     {
         
        
              a1=new AnalysisVertex((String)folder);
//              a.graph.addVertex (a1);
              vertices.add(grp+" "+(String)folder);
              mapList.put(a1,grp+"");
              
              System.out.println("Last and a1 "+last+" "+a1);
             // a.graph.addEdge(new DirectedSparseEdge(last,a1));
              edges.add((String)mapList.get(last)+"->"+grp);
              grp++;
         
        
         }
     
       else if(folder instanceof String && entryMap.containsKey(folder))
           a1=(AnalysisVertex)entryMap.get(folder);
       else
       {
         a1=(AnalysisVertex)folder;
         
       }
       last=a1;
     
      AnalysisVertex a2=new AnalysisVertex(yu+"");
      vertices.add(grp+" "+yu);
      groupMap.put(yu+"", indPrev);
      yu++;
      mapList.put(a2,grp+"");
      
      grp++;
      
      AnalysisVertex a3=new AnalysisVertex(yu+"");
      vertices.add(grp+" "+yu);
      groupMap.put(yu+"", ind);
      yu++;
      mapList.put(a3,grp+"");
      grp++;
      
      if(lno==1)
      {
          a2.set(nextTofind);
          entryMap.put(nextTofind, a2);
          last=a2;
      }
      else if(lno==2)
      {
          a3.set(nextTofind);
          entryMap.put(nextTofind, a3);
          last=a3;
      }
         
//          a.graph.addVertex (a2);
  //        a.graph.addVertex (a3);
         
          System.out.println("H T "+a1+" "+a2+" "+a3);
    //       a.graph.addEdge(new DirectedSparseEdge(a1,a2));
      //     a.graph.addEdge(new DirectedSparseEdge(a2,a3));
           
           edges.add(((String)mapList.get(a1))+"->"+((String)mapList.get(a2)));
           edges.add(((String)mapList.get(a2))+"->"+((String)mapList.get(a3)));
           
           if(folder instanceof String)
               return last;
           else return null;
          
        
 
 
 }
 public static boolean findEntryIn(Vector given,String a)  {
 
    Iterator ni=given.iterator();
    while(ni.hasNext())
    {
        String arr[]=((String)ni.next()).split(" ");
        
        if(arr.length==3&&arr[2].equals(a==null?nextTofind:a))
        {
            System.out.println("Mil "+arr[2]);
            return true;
        }
    
    }
    return false;
 
 }
 public void doSecondSetOfCorrelation(String sector)  {
 
 Enumeration e=hh2.keys();  
 Vector key=new Vector(hh2.keySet());
 Vector vs=new Vector(hh2.values());
 int vis=0,setFlag=0;
 while(e.hasMoreElements())
 {
    String r=(String)e.nextElement();
    System.out.println("For VCN "+r);
    int used=0;
   if(hs5.containsKey(r)) 
       used=(Integer)hs5.get(r);
   else
   {
        vis++;
        continue;
   }
    Vector vrs=(Vector)hh2.get(r);
    Vector vr=new Vector(vrs.subList(used,vrs.size()));
  int u=0;
    while(u<vr.size())
    {
        String h=(String)vr.get(u);
        System.out.println("SecondCorrelation For "+h);
        String arr[]=h.split(" ");
        u++;
    try
	{
                                Runtime rt = Runtime.getRuntime() ;
 				Process p = rt.exec("Disk.exe c "+arr[0]+" "+bootIndex) ;
 				BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream() ));
 				String ret=in.readLine();
                                boolean flag=false;
                                while(ret!=null)
                                {
                                    System.out.println(ret);
                                    if(ret.startsWith("Inuse"))
                                    {
                                        String ur[]=ret.split(" ");
                                        if(ur[1].equals("1"))
                                            flag=true;
                                    }
                                    if(ret.startsWith("Sequence")&&flag)
                                    {
                                        String ur[]=ret.split(" ");
                                        if(arr[1].equals(ur[1]) || Integer.parseInt(arr[1])<Integer.parseInt(ur[1]))
                                            break;
                                        /*else
                                        {
                                            if(Integer.parseInt(arr[1])<Integer.parseInt(ur[1]))
                                            {
                                                
                                                flag=false;
                                            
                                            }
                                        }*/
                                    }
                                    
                                    if(ret.startsWith("Parent")&&flag)
                                    {
                                        String ur[]=ret.split(" ");
                                         
                                        System.out.println("vval "+rootMFT.substring(0,rootMFT.length()-2)+(vval-10));
                                        if(!sector.equals(ur[1])&&!arr[0].equals(rootMFT.substring(0,rootMFT.length()-2)+(vval-10)))
                                        {
                                            System.out.println("Correlation Between "+sector+" and "+arr[0]);
                                            vertices.add(grp+" "+sector);
                                            grp++;
                                            edges.add(sector+"->"+ h);
                                            newHash.put(arr[0],sector);
                                        }
                                    
                                    }
                                
                                    ret=in.readLine();
                                }
    }
    catch(Exception e2)
    {}
    
    }
 }
 }
 public  void addChildsOfNode(TreeNodeM root)  {
  jp.removeAll();
  jp.validate();
  jp.repaint();
    Vector v=(Vector)hs.get(root.sector);
    int x=20,j=20;
    Iterator i=v.iterator();
    while(i.hasNext())
    {
        String newS=(String)i.next();
        String flag=(String)hs3.get(newS);
         JButtonExtended l=new JButtonExtended(newS) ;
         l.setMargin(new Insets(-3, -3, -3, -3));
          l.setFocusPainted(false);
        l.setContentAreaFilled(false); 
         l.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            
                 try
			{
                     
                               jLabel15.setText("n/a");
                               jLabel16.setText("n/a");
                               jLabel17.setText("n/a");
                               jLabel18.setText("n/a");
                               
                               jLabel11.setText("n/a");
                               jLabel12.setText("n/a");
                               jLabel13.setText("n/a");
                               jLabel14.setText("n/a");
                               
                               jLabel24.setText("          n/a");
                               jLabel25.setText("          n/a");
                               jLabel26.setText("          n/a");
                               jLabel27.setText("          n/a");
                              
                               jLabel36.setText("          n/a");
                               jLabel37.setText("          n/a");
                               jLabel38.setText("          n/a");
                               jLabel39.setText("          n/a");
                               
                               
                               
                               JButtonExtended  ll=(JButtonExtended ) e.getSource();
                                boolean flag=false;
 				Runtime rt = Runtime.getRuntime() ;
 				Process p = rt.exec("Disk.exe t "+ll.sector+" "+bootIndex) ;
 				BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream() ));
 				String h=in.readLine();
 				while(h!=null)
 				{
                                    if(!flag)
                                    {
                                       
                                        if(h.startsWith("cre"))
                                            jLabel15.setText(h.substring(3));
                                        if(h.startsWith("Mod"))
                                            jLabel16.setText(h.substring(3));
                                        if(h.startsWith("MFT"))
                                            jLabel17.setText(h.substring(3));
                                        if(h.startsWith("Acc"))
                                            jLabel18.setText(h.substring(3));
                                        else if(h.endsWith("16"))
                                        {
                                            flag=true;
                                        }
                                        
                                    }
                                    else
                                    {
                                        if(h.endsWith("48"))
                                        {
                                            flag=false;
                                        }
                                    if(h.startsWith("cre"))
                                            jLabel11.setText(h.substring(3));
                                        if(h.startsWith("Mod"))
                                            jLabel12.setText(h.substring(3));
                                        if(h.startsWith("MFT"))
                                            jLabel13.setText(h.substring(3));
                                        if(h.startsWith("Acc"))
                                            jLabel14.setText(h.substring(3));
                                    
                                    }
 					h=in.readLine();
 				}
 				if(logMFTHash.containsKey(ll.sector))
                                {
                                   
                                    IndexMace ii=(IndexMace)logMFTHash.get(ll.sector);
                                    jLabel36.setText(ii.Crea);
                                    jLabel37.setText(ii.MFT);
                                    jLabel38.setText(ii.Mod);
                                    jLabel39.setText(ii.last);
                                
                                }
 
 
				 p.destroy() ;
                 }
                 catch(Exception ex){
                     
                     ex.printStackTrace();
                 
                 }
            
            }
            
            
             
         });
         JLabel l2=new JLabel((String)hs2.get(newS));
         System.out.println("Label "+l2);
        if(flag.equalsIgnoreCase("dir"))
        {
            
             l.setIcon(new ImageIcon("new2.jpg"));
             
            if(root.flag)
            {
                TreeNodeM temp=new TreeNodeM((String)hs2.get(newS),newS);
            
            root.add(temp);
            }
           
        }
        else if(flag.equalsIgnoreCase("unused"))
        {
              l.setIcon(new ImageIcon("unuse.jpg"));
        }
        else
            l.setIcon(new ImageIcon("file.jpg"));
        
         if(x>600)
              {
                  j+=120;
                  x=20;
              }
             l2.setBounds(x,j+50,200,100);
             l.setBounds(x,j, 80, 80);
                 jp.add(l );
                 jp.add(l2);
                 jp.setPreferredSize(new Dimension(x,j+120));
                 jp.revalidate();
                 jp.repaint();
                  
                  jScrollPane2.revalidate();
                  jScrollPane2.repaint();
            jScrollPane2.updateUI();
             x+=200;
        
    }
    
    }
 public void valueChanged(TreeSelectionEvent event) {
    
   System.out.println(jTree1.getLastSelectedPathComponent());
   nameMFTvalueChanged=new Hashtable();
        TreeNodeM t=(TreeNodeM)jTree1.getLastSelectedPathComponent();
        selectedVCN="-1";
        try
			{
                                prw=new PrintWriter("rt.gdl");
                                boolean flag=false;
 				Runtime rt = Runtime.getRuntime() ;
 				Process p = rt.exec("Disk.exe t "+t.sector+" "+bootIndex) ;
                                System.out.println("Disk.exe t "+t.sector+" "+bootIndex);
 				BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream() ));
 				String h=in.readLine();
 				while(h!=null)
 				{
                                    
                                    if(!flag)
                                    {
                                       
                                        if(h.startsWith("cre"))
                                            jLabel15.setText(h.substring(3));
                                        if(h.startsWith("Mod"))
                                            jLabel16.setText(h.substring(3));
                                        if(h.startsWith("MFT"))
                                            jLabel17.setText(h.substring(3));
                                        if(h.startsWith("Acc"))
                                            jLabel18.setText(h.substring(3));
                                        else if(h.endsWith("16"))
                                        {
                                            flag=true;
                                        }
                                        
                                    }
                                    else
                                    {
                                        if(h.endsWith("48"))
                                        {
                                            flag=false;
                                        }
                                    if(h.startsWith("cre"))
                                            jLabel11.setText(h.substring(3));
                                        if(h.startsWith("Mod"))
                                            jLabel12.setText(h.substring(3));
                                        if(h.startsWith("MFT"))
                                            jLabel13.setText(h.substring(3));
                                        if(h.startsWith("Acc"))
                                            jLabel14.setText(h.substring(3));
                                    
                                    }
 					h=in.readLine();
 				}
 				if(logMFTHash.containsKey(t.sector))
                                {
                                   
                                    IndexMace ii=(IndexMace)logMFTHash.get(t.sector);
                                    jLabel36.setText(ii.Crea);
                                    jLabel37.setText(ii.MFT);
                                    jLabel38.setText(ii.Mod);
                                    jLabel39.setText(ii.last);
                                
                                }
 
 
				 p.destroy() ;
                                 
                                 Process q = rt.exec("Disk.exe p "+t.sector+" "+bootIndex+" "+(String)sectorToMFT.get(t.sector)) ;
                                 System.out.println("Disk.exe p "+t.sector+" "+bootIndex+" "+(String)sectorToMFT.get(t.sector));
                                 in = new BufferedReader(new InputStreamReader(q.getInputStream() ));
                                 h=in.readLine() ;
                                 Hashtable hh=new Hashtable();
                                 hs5=new Hashtable();
                                 Hashtable eItemp=null;
                                 entryIndex=null;
                                 entryIndex=new Hashtable();
                                 hh2.clear();
                                 String ar[];
                                 Vector vv,vv2=new Vector();
                                boolean deleted=false;
                                 Vector r=null;
                                 String tempS="",tempDn="";
                                 String lastVCN="",strVCN="";
                                 int i=0;
                                 hIndex=null;
                                 boolean flagset=false;
                                 hIndex=new Hashtable();
                                 IndexMace imace=null;
                                 Vector vNew=new Vector();
                                 prw.println("graph: {\nscaling: maxspect\ncolorentry 43: 210 255 201\ncolorentry 33: 161 215 244\nsplines: no\nlayout_algorithm: tree\nlayout_downfactor: 4\nsmanhattan_edges: yes\nxbase: 10\nybase: 10\ncolor: 33\nedge.color: 8\norientation: toptobottom");
                                 
                                 while(h!=null)
                                 {
                                    
                                     System.out.println(h);
                                     if(h.startsWith("ParentChild"))
                                     {
                                       ar=h.split(" ");  
                                     if(hh.containsKey(ar[1]))
                                     {
                                          vv =(Vector)hh.get(ar[1]);
                                          vv.add(ar[2]);
                                    }
                                     else
                                    {
                                           vv=new Vector();
                                           vv.add(ar[2]);
                                           hh.put(ar[1],vv);
                                     }
                                       if(ar.length==4)
                                       eItemp.put(ar[3],ar[2]);
                                       else
                                           eItemp.put("",ar[2]);
                                       
                                       vNew.add("edge: { sourcename: \""+tempDn.replace("\"","\\\"")+"\" targetname: \""+ar[2].replace("\"","\\\"")+"\" }\n");
                                    }
                                     
                                     if(h.startsWith("VCNNumber"))
                                     {
                                         if(hh2.containsKey(h.split(" ")[1]))
                                         {
                                         h=in.readLine() ;
                                         continue;
                                         }
                                     deleted=false;
                                     if(!lastVCN.equals(""))
                                         prw.println("}");
                                     vv2=new Vector();
                                     i=0;
                                     ar=h.split(" ");
                                     strVCN=ar[1];
                                     hh2.put(ar[1],vv2);
                                     lastVCN=ar[1];
                                      r=new Vector();
                                     hIndex.put(lastVCN,r);
                                     
                                     eItemp=new Hashtable();
                                     entryIndex.put(ar[1],eItemp);
                                     
                                      
                                     prw.println("graph: {\ntitle: \""+strVCN.replace("\"","\\\"")+"Gr"+"\"\nlabel: \""+strVCN.replace("\"","\\\"")+"\"\nwidth: 200\nxbase: 20 ybase: 20\ncolor: 43\nstatus: wrapped\norientation: toptobottom");
                                     prw.println("node: { title: \""+ strVCN.replace("\"","\\\"") +"\" }\n");
                                     }
                                     if(h.startsWith("FileReferenceNoToMFT"))
                                     {
                                     ar=h.split(" ");    
                                     if(ar[1].equals(rootMFT.substring(0,rootMFT.length()-2)+(vval-10)))
                                               flagset=true;
                                     else
                                         flagset=false;
                                     
                                     tempS=ar[1]+" "+ar[2];
                                     
                                     System.out.println("GOTTT "+tempS);
                                     }
                                     
                                     if(h.startsWith("EndOfAllocated"))
                                     {
                                     hs5.put(strVCN.replace("\"","\\\""),i);
                                     deleted=true;
                                     }
                                     System.out.println(h);
                                     
                                     if(h.startsWith("IndexName"))
                                     {
                                     
                                     ar=h.split(" ");
                                     if(ar.length==1 )
                                     {
                                         tempDn="WrongName";
                                         tempS+=" WrongName";
                                         //tempS="WrongName";
                                     }
                                     else
                                     {
                                         tempS+=" "+ar[1];
                                        // tempS=ar[1];
                                         tempDn=ar[1];
                                     }
                                    
                                     if((!vv2.contains(tempS)) && ((flagset && ar[1].equals("$MFT")) || !flagset) )
                                     {
                                     
                                         
                                         
                                             vv2.add(tempS);
                                             nameMFTvalueChanged.put((tempS.split(" "))[2],(tempS.split(" "))[0]);
                                        
                                         
                                     }
                                     
                                     
                                     prw.println("node: { title: \""+ (deleted?tempDn.replace("\"","\\\"")+":D":tempDn.replace("\"","\\\"")) +"\" }\n");
                                     prw.println("edge: { sourcename: \""+strVCN.replace("\"","\\\"")+"\" targetname: \""+(deleted?tempDn.replace("\"","\\\"")+":D":tempDn.replace("\"","\\\""))+"\" }\n");
                                     tempS="";
                                      imace=new IndexMace();
                                      i++;
                                     }
                                     
                                                               
                                      if(h.startsWith("cre"))
                                            imace.Crea=h.substring(3);
                                        if(h.startsWith("Mod"))
                                            imace.Mod=h.substring(3);
                                        if(h.startsWith("MFT"))
                                            imace.MFT=h.substring(3);
                                        if(h.startsWith("Acc"))
                                        {
                                            imace.last=h.substring(3);
                                            r.add(imace);
                                        }
                                                                        
                                     h=in.readLine() ;
                                 }
                                 prw.println("}");
                                  for(int ed=0;ed<vNew.size();ed++)
                                  {
                                        prw.println((vNew.get(ed)));
                                  
                                  }
                                  prw.println("}");
                                  prw.close();
                                  
                                 rootI.removeAllChildren();
                                 jTree2.updateUI();
                               
                                 TreeNodeM ch=addIndexNodes(hh,hh2);
                               
                                 if(ch!=null&&!ch.name.equals("IndexRoot"))
                                 {
                                     rootI.add(ch);
                                 }
                                
                                     Enumeration e=hh2.keys();
                                    while(e.hasMoreElements())
                                    {
                                        String sTemp=(String)e.nextElement();
                                        if(!temp.containsKey(sTemp)&&!sTemp.equals("IndexRoot"))
                                        rootI.add(new TreeNodeM(sTemp,"na"));
                                    }
                                 
                                  jTree2.updateUI();
                                  q.destroy();
                                  
                                 
}catch(Exception exc){exc.printStackTrace();}
        
    addChildsOfNode(t);
    t.flag=false;
    
  //  doSecondSetOfCorrelation(t.sector);
    if(analysisFlag)
        doFirstSetOfCorrelation(t.name);
   // addIcons();
    //jTree1.updateUI();
    }
 public TreeNodeM addIndexNodes(Hashtable hh,Hashtable hh2){
    
    
 
        Enumeration e=hh.keys();
  temp=new Hashtable();
    TreeNodeM n=null;
    while(e.hasMoreElements())
    {
    String hTemp=(String)e.nextElement();
    if(hTemp.equals("IndexRoot"))
    {
    n=rootI;
    }
    else
    n=new TreeNodeM(hTemp,"na");
    temp.put(hTemp,n);
    addChild(hh,hTemp,n,temp);
    
    }    
    
    Iterator i=(temp.values()).iterator();
    TreeNodeM m=null;
    while(i.hasNext())
    {
     m=(TreeNodeM)i.next();
     System.out.println(m+" "+m.getRoot());
    if(((TreeNodeM)m.getRoot()).name.equals(m.name))
        break;
            
    }
    
    
    return m;
    } 
 public void  addChild(Hashtable hh,String hTemp,TreeNodeM n,Hashtable temp)  {
    Vector u=(Vector)hh.get(hTemp);
    int i=0;
    TreeNodeM nTemp;
    while(i<u.size())
    {
        if(temp.containsKey((String)u.get(i)))
            nTemp=(TreeNodeM)temp.get((String)u.get(i));
        else
        {
            nTemp=new TreeNodeM((String)u.get(i),"na");
            temp.put((String)u.get(i),nTemp);
        }
        n.add(nTemp);
         i++;
    
    }
    }
 
 static public  void addAllToFile()  {
   
    r.println("graph: {\nscaling: maxspect\ncolorentry 43: 210 255 201\ncolorentry 33: 161 215 244\nsplines: no\nlayout_algorithm: tree\nlayout_downfactor: 4\nsmanhattan_edges: yes\nxbase: 10\nybase: 10\ncolor: 33\nedge.color: 8\norientation: toptobottom");
    Hashtable trmp=new Hashtable();  
    Iterator ii=vertices.iterator();
    while(ii.hasNext())
    {
       
        try
        {
        String tm=(String)ii.next();
        System.out.println("tm Vertices "+tm);
        String tmA[]=tm.split(" ");
        Vector tmp=new Vector();
        r.println("graph: {\ntitle: \""+tmA[1]+"\"\nlabel: \""+tmA[1]+"\"\nwidth: 200\nxbase: 20 ybase: 20\ncolor: 43\nstatus: boxed\norientation: toptobottom");
        r.println("graph: {\ntitle: \""+tmA[1]+"GR\"\nlabel: \""+tmA[1]+" Internal Graph\"\nwidth: 200\nxbase: 20 ybase: 20\ncolor: 43\nstatus: boxed\norientation: toptobottom");
        if(groupMap.containsKey(tmA[1]))
            tmp=(Vector)groupMap.get(tmA[1]);
        
        trmp.put(tmA[0],tmA[1]);
      
        for(int i=0;i<tmp.size();i++)
        {
            
            r.println("node: { title: \""+ tmp.get(i)+"\" }\n");
            r.println("edge: { sourcename: \""+tmA[1]+"\" targetname: \""+tmp.get(i)+"\" }\n");
            
        }
        r.println("}");
        r.println("}");
        }catch(Exception e)
        {
            
             r.println("}");
             r.println("}");
        }
    }
   
    ii=edges.iterator();
    while(ii.hasNext())
    {
        
        String tm=(String)ii.next();
        System.out.println("tm "+tm);
        String tmA[]=tm.split("->");
        r.println("edge: { sourcename: \""+(trmp.containsKey(tmA[0])?trmp.get(tmA[0]):tmA[0])+"\" targetname: \""+(trmp.containsKey(tmA[1])?trmp.get(tmA[1]):tmA[1])+"\" }\n");
    }
    r.println("}");
    r.close();
 
 }
    // Variables declaration - do not modify                     
    private javax.swing.JPanel jPanel1=new JPanel();
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    static javax.swing.JTree jTree1;
    static javax.swing.JTree jTree3;
    static TreeNodeM root;
    static Hashtable hs=new Hashtable();
    static Hashtable hIndex=new Hashtable();
    static Hashtable hs2=new Hashtable();
    static Hashtable hs3=new Hashtable();
    static TreeNodeM rootI;
    static TreeNodeM root3=new TreeNodeM("IndexRoot","");
    static String selectedVCN;
    Hashtable hh2=new Hashtable();
    static Hashtable entryMap=new Hashtable();
    static Hashtable groupMap=new Hashtable();
    static DotThread dt=new DotThread();
    static InterruptThread it=new InterruptThread();
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel40;
    static PrintWriter r ;
    static Vector vertices=new Vector();
    static Vector edges=new Vector();
    static int grp=1;
    static Hashtable mapList=new Hashtable();
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane3;
    public  Hashtable temp=new Hashtable();
    static Hashtable sectorToMFT=new Hashtable();
    static Hashtable logMFTHash=new Hashtable();
    static Hashtable seqLogFileMFT =new Hashtable();
    static LSNTreeMap LSNSector=new LSNTreeMap();
    static Hashtable nameMFTvalueChanged=new Hashtable();
    static Hashtable logFileMFTEarliest =new Hashtable();
    static Hashtable MFTSeq =new Hashtable();
    public static String bootIndex,rootMFT;
    public static Hashtable entryIndex=new Hashtable();
    private javax.swing.JTree jTree2;
    static TreeNodeM lastVisited=null;
    JMenuBar mB = new JMenuBar();
    static Hashtable newHash=new Hashtable();
    static Analysis a;
    static PrintWriter prw;
    static AnalysisVertex last=null;
    static Hashtable relation=new Hashtable();
    String part=null;
    static TreeMap tmap=new TreeMap();
    static Hashtable hs4=new Hashtable();
    static Hashtable hs5=new Hashtable();
    JPanel jp=new JPanel();
    static int yu=0;
    // End of variables declaration                   
    
}

class TreeNodeM extends DefaultMutableTreeNode{
   String sector;
   
    String name;
    boolean flag=true;
  
    TreeNodeM(String name,String sector)
    {
        super(name);
        this.sector=sector;
        this.name=name;
         
    }
    
   
    
    @Override
    public String toString()
    {
        return name;
    }
}

class  JButtonExtended extends JButton{
    
    String sector;
    int seqNo;
    
    JButtonExtended(String sector)
    {
    super();
    this.sector=sector;
    
    }

    JButtonExtended(String sector,int uu)
    {
    super();
    this.sector=sector;
    seqNo=uu;
    }

}

class AnalysisVertex {
    
    String name;
    
    AnalysisVertex(String name)
    {
    this.name=name;
    
    }
    
    public void set(String name)
    {
        this.name=name;
    }
    public String toString()
    {
        return name;
    }
}
class IndexMace {
    
    String Crea;
    String Mod;
    String MFT;
    String last;
}

class LSNString implements Comparable
{
     String val;
     
     public  LSNString(String s)
     {
   	 val=s;
     }
     
     public String toString()
     {
        return val;
     }
     
     public int compareTo(Object arg)
     {
        LSNString tmp=(LSNString)arg;
        if(val.length()!=tmp.val.length())
            return (val.length()-tmp.val.length());
        else 
            return val.compareTo(tmp.val);
            
            
     }

}

class LSNTreeMap extends TreeMap{
    Vector key;
     Vector value;
    TreeMap p;
     public LSNTreeMap()
     {
        key=new  Vector();
        value=new  Vector();
        p=new TreeMap();
     }       
     
     public Object put(Object k,Object v)
     {
        if(key.contains(k))
        {
            int i=key.indexOf(k);
            key.remove(k);
            value.remove(i);
        }
        else if( value.contains(v))
        {
            int i=value.indexOf(v);
            value.remove(v);
            Object valKey=key.get(i);
            p.remove(valKey);
            key.remove(i);
        }
        key.add(k);
        value.add(v);
        
        p.put(k,v);
        
        //Collections.sort(key);
        
     return null;
     }
     
     public Object get(Object k)
     {
        return p.get(k);
     }
     
     public Collection values()
     {
        return p.values();
     }
     
     public String toString()
     {
     return p.toString();
     }
}


class DotThread extends Thread{
    
    public void run()
    {
     while(true)
     {
        Analysis.jtext.append(".");
        try{
            sleep(1500);
           
        }catch(Exception e)
        {
            e.printStackTrace();
        }
     }
    }
}

class InterruptThread extends Thread{
    
    public void run()
    {
        try{
            sleep(1500);
            SwingUtilities.invokeLater(Form.dt);
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    
    }
}




